package com.bjb.vr.operation.controller;

import com.bjb.vr.common.ao.SysConfigAo;
import com.bjb.vr.common.constant.ThreadLocalConstant;
import com.bjb.vr.common.dto.SysConfig;
import com.bjb.vr.common.result.BaseErrorCode;
import com.bjb.vr.common.result.BaseResult;
import com.bjb.vr.common.result.CommonResult;
import com.bjb.vr.common.service.SysConfigService;
import com.bjb.vr.common.utils.ThreadLocalUtil;
import com.bjb.vr.common.vo.DevResSyncStatusVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version 1.0.0
 * @description:系统配置管理
 * @author: caihaibo
 * @createDate: 2022/9/20
 */

@RestController
@RequestMapping("/api/operation/v1")
public class SysConfigController {

	@Autowired
	SysConfigService sysConfigService;

	/**
	 * 客户配置管理-设备资源同步开关
	 * @param sysConfigAo
	 * @return
	 */
	@PostMapping("/updateDevResSyncStatus")
	public BaseResult updateDevResSyncStatus(@RequestBody SysConfigAo sysConfigAo){
		boolean success = sysConfigService.updateDevResSyncStatus(sysConfigAo);
		if (!success) {
			return CommonResult.Fail(BaseErrorCode.ERROR_ADD);
		}
		return CommonResult.Ok();
	}

	/**
	 * 客户配置管理-获取设备资源同步开关
	 * @param sysConfigAo
	 * @return
	 */
	@PostMapping("/getDevResSyncStatus")
	public BaseResult<DevResSyncStatusVo> getDevResSyncStatus(@RequestBody SysConfigAo sysConfigAo){
		ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, true);
		DevResSyncStatusVo devResSyncStatusVo = null;
		devResSyncStatusVo = sysConfigService.getDevResSyncStatus(sysConfigAo);
		ThreadLocalUtil.set(ThreadLocalConstant.NO_TENANT_ID_VERIFY, false);
		return CommonResult.Ok().setResult(devResSyncStatusVo);
	}
}
